package com.example.practice.creative;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.practice.R;

public class SellerAdapter extends BaseAdapter {
	private List<String> itemsList = new ArrayList<String>();

	public SellerAdapter( List<String> itemsList) {
		 this.itemsList = itemsList;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return itemsList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(arg2.getContext()).inflate(R.layout.item_seller, null);
		
		EditText price = (EditText)view.findViewById(R.id.edt_price);
		Button button = (Button)view.findViewById(R.id.btn_save);
		TextView name = (TextView)view.findViewById(R.id.tv_name );
		name.setText(itemsList.get(arg0));
		price.setTag(itemsList.get(arg0));
		button.setTag(price);
		
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Button  button = (Button) arg0;
				EditText editText = (EditText)button.getTag();
				String name = editText.getTag().toString();
				SPUtil.setFloat(name, Float.parseFloat(editText.getText().toString()));
			}
		});
		
		price.setText(SPUtil.getFloat(itemsList.get(arg0)) + "");
		return view;

	}
	
}
